home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-31 | 10.5 KB | 227 lines | [TEXT/MPCC] |
- // qd3d sample code - Nick Thompson DEVSUPPORT, 23rd March 1995
- //
- // © 1995, Apple Computer Inc., All Rights Reserved
- //
- #include "QD3D.h"
- #include "QD3DErrors.h"
-
- #include "MyErrorHandler.h"
-
- // define a table for all of the QuickDraw 3D error codes
- struct {
- TQ3Warning theWarning ;
- char *theString ;
- } warningTable[] = {
- /* General System */
- kQ3WarningInternalException, "kQ3WarningInternalException",
- /* Object Warnings */
- kQ3WarningNoObjectSupportForDuplicateMethod, "kQ3WarningNoObjectSupportForDuplicateMethod",
- kQ3WarningNoObjectSupportForWriteMethod, "kQ3WarningNoObjectSupportForWriteMethod",
- kQ3WarningNoObjectSupportForReadMethod, "kQ3WarningNoObjectSupportForReadMethod",
- kQ3WarningNoObjectSupportForDrawMethod, "kQ3WarningNoObjectSupportForDrawMethod",
- kQ3WarningUnknownElementType, "kQ3WarningUnknownElementType",
- kQ3WarningTypeAndMethodAlreadyDefined, "kQ3WarningTypeAndMethodAlreadyDefined",
- kQ3WarningTypeIsOutOfRange, "kQ3WarningTypeIsOutOfRange",
- kQ3WarningTypeHasNotBeenRegistered, "kQ3WarningTypeHasNotBeenRegistered",
- /* IO Warnings */
- kQ3WarningFilePointerResolutionFailed, "kQ3WarningFilePointerResolutionFailed",
- kQ3WarningStringExceedsMaximumLength, "kQ3WarningStringExceedsMaximumLength",
- /* Memory Warnings */
- kQ3WarningLowMemory, "kQ3WarningLowMemory",
- kQ3WarningPossibleMemoryLeak, "kQ3WarningPossibleMemoryLeak",
- /* View Warnings */
- kQ3WarningViewTraversalInProgress, "kQ3WarningViewTraversalInProgress",
- kQ3WarningNonInvertibleMatrix, "kQ3WarningNonInvertibleMatrix",
- /* Quaternion Warning */
- kQ3WarningQuaternionEntriesAreZero, "kQ3WarningQuaternionEntriesAreZero",
- /* Renderer Warning */
- kQ3WarningFunctionalityNotSupported, "kQ3WarningFunctionalityNotSupported",
- kQ3WarningLastWarning, "kQ3WarningLastWarning"
- } ;
-
-
- struct {
- TQ3Error theError ;
- char *theString ;
- } errorTable[] = {
- /* Fatal Errors */
- kQ3ErrorInternalError, "kQ3ErrorInternalError",
- kQ3ErrorNoRecovery, "kQ3ErrorNoRecovery",
- kQ3ErrorLastFatalError, "kQ3ErrorLastFatalError",
- /* System Errors */
- kQ3ErrorNotInitialized, "kQ3ErrorNotInitialized",
- kQ3ErrorAlreadyInitialized, "kQ3ErrorAlreadyInitialized",
- kQ3ErrorUnimplemented, "kQ3ErrorUnimplemented",
- kQ3ErrorRegistrationFailed, "kQ3ErrorRegistrationFailed",
- /* OS Errors */
- kQ3ErrorUnixError, "kQ3ErrorUnixError",
- kQ3ErrorMacintoshError, "kQ3ErrorMacintoshError",
- kQ3ErrorX11Error, "kQ3ErrorX11Error",
- /* Memory Errors */
- kQ3ErrorMemoryLeak, "kQ3ErrorMemoryLeak",
- kQ3ErrorOutOfMemory, "kQ3ErrorOutOfMemory",
- /* Parameter errors */
- kQ3ErrorNULLParameter, "kQ3ErrorNULLParameter",
- kQ3ErrorParameterOutOfRange, "kQ3ErrorParameterOutOfRange",
- kQ3ErrorInvalidParameter, "kQ3ErrorInvalidParameter",
- kQ3ErrorInvalidData, "kQ3ErrorInvalidData",
- kQ3ErrorAcceleratorAlreadySet, "kQ3ErrorAcceleratorAlreadySet",
- kQ3ErrorVector3DNotUnitLength, "kQ3ErrorVector3DNotUnitLength",
- /* Object Errors */
- kQ3ErrorInvalidObject, "kQ3ErrorInvalidObject",
- kQ3ErrorInvalidObjectClass, "kQ3ErrorInvalidObjectClass",
- kQ3ErrorInvalidObjectType, "kQ3ErrorInvalidObjectType",
- kQ3ErrorInvalidObjectName, "kQ3ErrorInvalidObjectName",
- kQ3ErrorObjectClassInUse, "kQ3ErrorObjectClassInUse",
- kQ3ErrorAccessRestricted, "kQ3ErrorObjectClassInUse",
- kQ3ErrorMetaHandlerRequired, "kQ3ErrorMetaHandlerRequired",
- kQ3ErrorNeedRequiredMethods, "kQ3ErrorNeedRequiredMethods",
- kQ3ErrorNoSubClassType, "kQ3ErrorNoSubClassType",
- kQ3ErrorUnknownElementType, "kQ3ErrorUnknownElementType",
- kQ3ErrorNotSupported, "kQ3ErrorNotSupported",
- /* Extension Errors */
- kQ3ErrorNoExtensionsFolder, "kQ3ErrorNoExtensionsFolder",
- kQ3ErrorExtensionError, "kQ3ErrorExtensionError",
- kQ3ErrorPrivateExtensionError, "kQ3ErrorPrivateExtensionError",
- /* Geometry Errors */
- kQ3ErrorDegenerateGeometry, "kQ3ErrorDegenerateGeometry",
- kQ3ErrorGeometryInsufficientNumberOfPoints, "kQ3ErrorGeometryInsufficientNumberOfPoints",
- /* IO Errors */
- kQ3ErrorEndOfFile, "kQ3ErrorEndOfFile",
- kQ3ErrorFileCancelled, "kQ3ErrorFileCancelled",
- kQ3ErrorInvalidMetafile, "kQ3ErrorInvalidMetafile",
- kQ3ErrorInvalidMetafilePrimitive, "kQ3ErrorInvalidMetafilePrimitive",
- kQ3ErrorInvalidMetafileLabel, "kQ3ErrorInvalidMetafileLabel",
- kQ3ErrorInvalidMetafileObject, "kQ3ErrorInvalidMetafileObject",
- kQ3ErrorInvalidMetafileSubObject, "kQ3ErrorInvalidMetafileSubObject",
- kQ3ErrorInvalidSubObjectForObject, "kQ3ErrorInvalidSubObjectForObject",
- kQ3ErrorUnresolvableReference, "kQ3ErrorUnresolvableReference",
- kQ3ErrorUnknownObject, "kQ3ErrorUnknownObject",
- kQ3ErrorStorageInUse, "kQ3ErrorStorageInUse",
- kQ3ErrorStorageAlreadyOpen, "kQ3ErrorStorageAlreadyOpen",
- kQ3ErrorStorageNotOpen, "kQ3ErrorStorageNotOpen",
- kQ3ErrorStorageIsOpen, "kQ3ErrorStorageIsOpen",
- kQ3ErrorFileAlreadyOpen, "kQ3ErrorFileAlreadyOpen",
- kQ3ErrorFileNotOpen, "kQ3ErrorFileNotOpen",
- kQ3ErrorFileIsOpen, "kQ3ErrorFileIsOpen",
- kQ3ErrorBeginWriteAlreadyCalled, "kQ3ErrorBeginWriteAlreadyCalled",
- kQ3ErrorBeginWriteNotCalled, "kQ3ErrorBeginWriteNotCalled",
- kQ3ErrorEndWriteNotCalled, "kQ3ErrorEndWriteNotCalled",
- kQ3ErrorReadStateInactive, "kQ3ErrorReadStateInactive",
- kQ3ErrorStateUnavailable, "kQ3ErrorStateUnavailable",
- kQ3ErrorWriteStateInactive, "kQ3ErrorWriteStateInactive",
- kQ3ErrorSizeNotLongAligned, "kQ3ErrorSizeNotLongAligned",
- kQ3ErrorFileModeRestriction, "kQ3ErrorFileModeRestriction",
- kQ3ErrorInvalidHexString, "kQ3ErrorInvalidHexString",
- kQ3ErrorWroteMoreThanSize, "kQ3ErrorWroteMoreThanSize",
- kQ3ErrorWroteLessThanSize, "kQ3ErrorWroteLessThanSize",
- kQ3ErrorReadLessThanSize, "kQ3ErrorReadLessThanSize",
- kQ3ErrorReadMoreThanSize, "kQ3ErrorReadMoreThanSize",
- kQ3ErrorSizeMismatch, "kQ3ErrorSizeMismatch",
- kQ3ErrorStringExceedsMaximumLength, "kQ3ErrorStringExceedsMaximumLength",
- kQ3ErrorValueExceedsMaximumSize, "kQ3ErrorValueExceedsMaximumSize",
- kQ3ErrorNonUniqueLabel, "kQ3ErrorNonUniqueLabel",
- kQ3ErrorUnmatchedEndGroup, "kQ3ErrorUnmatchedEndGroup",
- /* View errors */
- kQ3ErrorViewNotStarted, "kQ3ErrorViewNotStarted",
- kQ3ErrorViewIsStarted, "kQ3ErrorViewIsStarted",
- kQ3ErrorRendererNotSet, "kQ3ErrorRendererNotSet",
- kQ3ErrorRenderingIsActive, "kQ3ErrorRenderingIsActive",
- kQ3ErrorImmediateModeUnderflow, "kQ3ErrorImmediateModeUnderflow",
- kQ3ErrorDisplayNotSet, "kQ3ErrorDisplayNotSet",
- kQ3ErrorCameraNotSet, "kQ3ErrorCameraNotSet",
- kQ3ErrorDrawContextNotSet, "kQ3ErrorDrawContextNotSet",
- kQ3ErrorNonInvertibleMatrix, "kQ3ErrorNonInvertibleMatrix",
- kQ3ErrorRenderingNotStarted, "kQ3ErrorRenderingNotStarted",
- kQ3ErrorPickingNotStarted, "kQ3ErrorPickingNotStarted",
- kQ3ErrorBoundsNotStarted, "kQ3ErrorBoundsNotStarted",
- kQ3ErrorDataNotAvailable, "kQ3ErrorDataNotAvailable",
- kQ3ErrorNothingToPop, "kQ3ErrorNothingToPop",
- /* Renderer Errors */
- kQ3ErrorUnknownStudioType, "kQ3ErrorUnknownStudioType",
- kQ3ErrorAlreadyRendering, "kQ3ErrorAlreadyRendering",
- kQ3ErrorStartGroupRange, "kQ3ErrorStartGroupRange",
- kQ3ErrorUnsupportedGeometryType, "kQ3ErrorUnsupportedGeometryType",
- kQ3ErrorInvalidGeometryType, "kQ3ErrorInvalidGeometryType",
- kQ3ErrorUnsupportedFunctionality, "kQ3ErrorUnsupportedFunctionality",
- /* Group Errors */
- kQ3ErrorInvalidPositionForGroup, "kQ3ErrorInvalidPositionForGroup",
- kQ3ErrorInvalidObjectForGroup, "kQ3ErrorInvalidObjectForGroup",
- kQ3ErrorInvalidObjectForPosition, "kQ3ErrorInvalidObjectForPosition",
- /* Transform Errors */
- kQ3ErrorScaleOfZero, "kQ3ErrorScaleOfZero",
- /* String Errors */
- kQ3ErrorBadStringType, "kQ3ErrorBadStringType",
- /* Attribute Errors */
- kQ3ErrorAttributeNotContained, "kQ3ErrorAttributeNotContained",
- kQ3ErrorAttributeInvalidType, "kQ3ErrorAttributeInvalidType",
- /* Camera Errors */
- kQ3ErrorInvalidCameraValues, "kQ3ErrorInvalidCameraValues",
- /* DrawContext Errors */
- kQ3ErrorBadDrawContextType, "kQ3ErrorBadDrawContextType",
- kQ3ErrorBadDrawContextFlag, "kQ3ErrorBadDrawContextFlag",
- kQ3ErrorBadDrawContext, "kQ3ErrorBadDrawContext",
- kQ3ErrorUnsupportedPixelDepth, "kQ3ErrorUnsupportedPixelDepth",
- kQ3ErrorLastError, "kQ3ErrorLastError"
- } ;
-
-
-
- //-------------------------------------------------------------------------------------------
- // MyErrorHandler - handle warnings from QuickDraw 3d
- void MyErrorHandler( TQ3Error sticky, TQ3Error latest, long refCon )
- {
- register short byteCount = 0;
- const short bufsiz = 512 ;
- char buf[bufsiz] ;
- short index = sticky - kQ3ErrorInternalError ;
-
- // if the error is out of range, then just tell us that something
- // "unknown" happened. Otherwise look up the error from the table.
-
- sprintf(&buf[1], "QuickDraw 3D Error: %d (%s)\n",
- sticky,
- ( sticky < kQ3ErrorInternalError || sticky > kQ3ErrorLastError ) ? "Unknown Error Code" : errorTable[ index ].theString);
-
- // get the length of the c string we placed in the buffer
- for( byteCount = 1; buf[byteCount] != '\0' && byteCount < 512 ; byteCount++)
- ;
- // which in effect makes a pascal string
- buf[0] = byteCount ;
-
- // and display the error string
- DebugStr( (unsigned char *)buf ) ;
- }
-
-
- //-------------------------------------------------------------------------------------------
- // MyErrorHandler - handle warnings from QuickDraw 3d
- void MyWarningHandler( TQ3Warning sticky, TQ3Warning latest, long refCon )
- {
- register short byteCount = 0;
- const short bufsiz = 512 ;
- char buf[bufsiz] ;
- short stickyIndex = sticky - kQ3WarningInternalException ;
- short latestIndex = latest - kQ3WarningInternalException ;
-
- // if the error is out of range, then just tell us that something
- // "unknown" happened. Otherwise look up the error from the table.
-
- sprintf(&buf[1], "QuickDraw 3D warning: Could not %d (%s) Because %d (%s)\n",
- sticky,
- ( sticky < kQ3WarningInternalException || sticky > kQ3WarningLastWarning ) ? "Unknown Warning Code" : warningTable[ stickyIndex ].theString,
- latest,
- ( latest < kQ3WarningInternalException || latest > kQ3WarningLastWarning ) ? "Unknown Warning Code" : warningTable[ latestIndex ].theString ) ;
-
- // get the length of the c string we placed in the buffer
- for( byteCount = 1; buf[byteCount] != '\0' && byteCount < 512 ; byteCount++)
- ;
-
- // which in effect makes a pascal string
- buf[0] = byteCount ;
-
- // and display the error string
- DebugStr( (unsigned char *)buf ) ;
- }
-
-